library(leaflet)
library(leafpop)
library(leaflet.mapboxgl) # remotes::install_github("rstudio/leaflet.mapboxgl")Default
Far (zoom = 10)
leaflet() %>% addTiles() %>%
setView(lng = -74.000060, lat = 40.730910, zoom = 10) %>%
addMarkers(lng = -74.000060, lat = 40.730910)Close (zoom = 100)
leaflet() %>% addTiles() %>%
setView(lng = -74.000060, lat = 40.730910, zoom = 100) %>%
addMarkers(lng = -74.000060, lat = 40.730910)pal <- colorBin("viridis", domain = quakes$mag , bins = c(4,5,6,10))
quakes %>%
leaflet() %>% addTiles() %>%
addCircleMarkers(radius = 6,
color = ~pal(mag),
fillOpacity = 0.5,
stroke = FALSE) %>%
addLegend(pal = pal,
values = ~mag,
opacity = 0.7,
title = "Magnitude",
position = "bottomright")content <- paste(sep = "<br/>",
"<b><a href='https://furmancenter.org/'>NYU Furman Center</a></b>",
"139 MacDougal Street, 2nd floor",
"New York, NY 10012")
leaflet() %>% addTiles() %>%
addMarkers(lng = -74.000060, lat = 40.730910,
popup = content)labels <- sprintf("Magnitude: %g",
quakes$mag) %>%
lapply(htmltools::HTML)
quakes %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(radius = 6,
color = ~pal(mag),
fillOpacity = 0.5,
stroke = FALSE,
label = labels) %>%
addLegend(pal = pal,
values = ~mag,
opacity = 0.7,
title = "Magnitude",
position = "bottomright")leaflet() %>% addTiles() %>% setView(-118.456554, 34.09, 13) %>%
addMarkers(lng = -118.456554, lat = 34.105,
label = "Default Label",
labelOptions = labelOptions(noHide = T)) %>%
addMarkers(lng = -118.456554, lat = 34.095,
label = "Label w/o surrounding box",
labelOptions = labelOptions(noHide = T,
textOnly = TRUE)) %>%
addMarkers(lng = -118.456554, lat = 34.085,
label = "label w/ textsize 15px",
labelOptions = labelOptions(noHide = T,
textsize = "15px")) %>%
addMarkers(lng = -118.456554, lat = 34.075,
label = "Label w/ custom CSS style",
labelOptions = labelOptions(noHide = T,
direction = "bottom",
style = list("color" = "red",
"font-family" = "serif",
"font-style" = "italic",
"box-shadow" = "3px 3px rgba(0,0,0,0.25)",
"font-size" = "12px",
"border-color" = "rgba(0,0,0,0.5)")))pal <- colorBin("viridis", domain = population$legend_value)
labels <- sprintf("<strong>%s</strong><br/>Population: %s",
population$NAME, population$pretty_estimate) %>% lapply(htmltools::HTML)
population %>%
leaflet() %>% addTiles() %>% setView(-96, 37.8, 4) %>%
addPolygons(fillColor = ~pal(legend_value),
fillOpacity = 0.7,
color = "white",
weight = 1,
opacity = 1,
smoothFactor = 0.5,
highlight = highlightOptions(weight = 5,
color = "white",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(style = list("font-weight" = "normal",
padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal,
values = ~legend_value,
opacity = 0.7,
title = "Population (Millions)",
position = "bottomright")